/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package casino;

import java.text.MessageFormat;

/**
 * Class of objects that holds its bet name and payout odds.
 * 
 * @author  amaghfur
 * @since   1.0
 */
public class Outcome {
    
    /** bet name */
    private String name;
    /** numerator odds */
    private int numerator;
    /** denominator odds */
    private int denominator;
    
    /**
     * Constructor specifying bet name and odds.
     * 
     * @param startName
     * @param startNumerator
     * @param startDenominator
     */
    public Outcome(String startName, int startNumerator, int startDenominator) {
    	name = startName;
        numerator = startNumerator;
        denominator = startDenominator;
    }
    
    /**
     * Constructor specifying bet name and odds (with default denominator of 1)
     * 
     * @param   startName   name of bet
     * @param   startOdds   odds of bet
     */
    public Outcome(String startName, int startOdds) {
        this(startName, startOdds, 1);
    }
    
    /**
     * Getter for name.
     * 
     * @return  name 
     */
    public String getName() {
        return name;
    }
    
    /**
     * Getter for odds.
     * 
     * @return  odds 
     */
    public Rational getOdds() {
        return new Rational(numerator, denominator);
    }
    
    /**
     * Returns payout for the amount argument based on this outcome.
     * 
     * @param   amount  amount the payout is based on
     * @return          the payout amount
     */
    public Rational winAmount(int amount) {
    	Rational odds = new Rational(numerator, denominator);
    	Rational rationalAmount = new Rational(amount, 1);
        return odds.times(rationalAmount);
    }
    
    /**
     * Returns true if this outcome's matches the outcome argument.
     * 
     * @param   other   outcome being compared to
     * @return          true if same outcome
     */
    public boolean equals(Outcome other) {
        return (other.name).equals(name);
    }

    /**
     * Creates easy-to-read representation of this outcome.
     * Example: "straight (32:1)" without quotes.
     * 
     * @return      an easy-to-read representation of this outcome
     */
    @Override
    public String toString() {
        Object[] values = { name, new Integer(numerator), new Integer(denominator) };
        String msgTempl = "{0} ({1}:{2})";
        return MessageFormat.format(msgTempl, values);
    }
    
}